function openAddPermissionPopup(){
	jQuery('#basic-modal-content-permission').modal();
}
function savePermission(){
	if(validate()){
		if(jQuery('#permission_id').val() == ""){
			jQuery.post("./admin/database_definition/permissions/ajax_permission_save", { permission: jQuery("#permission").val()},
				function(data) {
					res = eval('(' + data + ')');
					if(res.result){
						jQuery('#escort-option').tabs( "load" , 1 );
						jQuery.modal.close();
						if(jQuery('#content-body div.alert').length){
							jQuery('#content-body div.alert').remove();
						}
						jQuery('#content-body').prepend('<div class="alert success">'+ res.message+'</div>');
					}else{
						if(jQuery('form#add-permission-form section.item div.alert').length){
							jQuery('form#add-permission-form section.item div.alert').remove();
						}
						jQuery('form#add-permission-form section.item').prepend('<div class="alert error">'+ res.message+'</div>');
					}
				}
			);
		}else{
			jQuery.post("./admin/database_definition/permissions/ajax_permission_update", {id: jQuery('#permission_id').val(), permission: jQuery("#permission").val()},
				function(data) {
					res = eval('(' + data + ')');
					if(res.result){
						jQuery('#permission_id').val("");
						jQuery("#permission").val("");
						jQuery('#escort-option').tabs( "load" , 1 );
						jQuery.modal.close();
						if(jQuery('#content-body div.alert').length){
							jQuery('#content-body div.alert').remove();
						}
						jQuery('#content-body').prepend('<div class="alert success">'+ res.message+'</div>');
					}else{
						if(jQuery('form#add-permission-form section.item div.alert').length){
							jQuery('form#add-permission-form section.item div.alert').remove();
						}
						jQuery('form#add-permission-form section.item').prepend('<div class="alert error">'+ res.message+'</div>');
					}
			 	}
			);
		}
	}else{
		return false;
	}
}
function validate(){
	return true;
}
function editPermission(id){
	jQuery.post("./admin/database_definition/permissions/ajax_permission_get", { id: id},
		function(data) {
			res = eval('(' + data + ')');
			jQuery('#basic-modal-content-permission').modal();
			jQuery('#permission').val(res.name);
			jQuery('#permission_id').val(res.id);
	 	}
	);
	return false;
}
function deletePermission(id, message){
	confirm(message, function () {
		jQuery.post("./admin/database_definition/permissions/ajax_permission_delete", { id: id},
			function(data) {
				jQuery('#escort-option').tabs( "load" , 1 );
				if(jQuery('#content-body div.alert').length){
					jQuery('#content-body div.alert').remove();
				}
				jQuery('#content-body').prepend('<div class="alert success">'+ data.message+'</div>');
		 	},"json"
		);
		return false;
	});
	return false;
}